<template>
  <div class="entrance-box">
    <div class="top">来访人员基本信息</div>

    <div class="info-box">
      <div class="info-one" v-for="(people, index) in applyList" :key="index">
        <div class="info-left">
          <img :src="people.path" alt="" />
        </div>
        <div class="info-right">
          <div class="item">身份: {{people.userType === 1 ? '管理员' : people.userType === 2 ? '员工' : people.userType === 3 ? '陌生人' : '' }}</div>
          <div class="item">姓名: {{people.workerName ? people.workerName : '陌生人'}}</div>

          <div class="item">联系方式: {{people.mobile}}</div>

          <div class="item">仓库名称: {{people.depotName}} ({{ people.doorId }}号门)</div>
          <div class="item">来访时间: {{people.appTime}}</div>
        </div>
      </div>
    </div>

    <div class="btn-list" v-if="applyList && applyList[0]&& applyList[0].status === 0">
      <div class="reset" @click="approval(2)">拒绝</div>
      <div class="submit" @click="approval(1)">同意</div>
    </div>
  </div>
</template>

<script>
import { getEntranceApplyList, entranceAppLicensing } from "@/api/inventory/index";
export default {
  // 入门申请 demo - 来访人员信息
  name: "entry-application",
  data() {
    return {
      applyList: [],
      num: null, // 批次号
    };
  },
  created() {
    this.num = this.$route.query.num
    this.getLog();
  },
  methods: {
    getLog() {
      const data = {
        num: this.num
      };
      const params = {};
      getEntranceApplyList(data, params).then((res) => {
        res.data.map(e => {
          e.createdOn = e.createdOn && this.$moment(e.createdOn * 1000).format(
              "YYYY-MM-DD HH:mm:ss"
            );
        })
        this.applyList = res.data
      });
    },
    // 审批
    approval(status) {
      // 加载框
      const loading = this.$loading({
        lock: true,
        text: "加载中",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.5)",
      });
      const params = {
        status: status,
        num: this.num
      };

      entranceAppLicensing(params).then((res) => {
        this.getLog()
        this.$message.success(status == 1 ? '审批已同意' : '审批已拒绝')
        loading.close();
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.entrance-box {
  padding: 10px;
  background-color: #f5f5f5;
  height: 100vh;
  .top {
    line-height: 45px;
    background-color: #f88123;
    color: #fff;
    text-align: center;
    border-radius: 10px 10px 0 0;
    font-size: 16px;
  }
  .info-box {
    .info-one {
      border: 1px solid #999;
      background-color: #fff;
      border-radius: 20px;
      box-shadow: 0 2px 10px rgba($color: #000000, $alpha: 0.3);
      margin-top: 15px;
      padding: 15px;
      box-sizing: border-box;
      display: flex;
      .info-left {
        width: 30%;
        img {
          width: 80px;
          height: 80px;
        }
      }
      .info-right {
        line-height: 22px;
      }
    }
  }

  .btn-list {
    display: flex;
    justify-content: space-between;
    line-height: 40px;
    margin-top: 40px;
    padding: 0 10px;
    div {
      width: 45%;
      color: #fff;
      text-align: center;
      font-size: 16px;
      cursor: pointer;
      border-radius: 20px;
    }
    .reset {
      background-color: #666;
    }
    .submit {
      background-color: #f88123;
    }
  }
}
</style>
